home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4869 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.2 KB

  1. Path: news.uni-jena.de!news
  2. From: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Aborting Constructors, Part II
  5. Date: 1 Feb 1996 11:48:13 GMT
  6. Organization: Lehrstuhl fuer Rechnerarchitektur- und kommunikation, FSU Jena
  7. Message-ID: <4eq99t$fpu@fsuj01.rz.uni-jena.de>
  8. References: <4eoeck$t6n@news.ios.com>
  9. Reply-To: mkt@isun04.inf.uni-jena.de
  10. NNTP-Posting-Host: isun07.inf.uni-jena.de
  11.  
  12. > test::test(){
  13. >     cout << "constructing object\n";
  14. >     delete this;
  15. >     throw(xmsg(string("deleted the object!\n")));
  16. > }
  17.  
  18. I am sure that using delete on this is not allowed in C++.
  19. I can remember that Borland is a little bit strange in those things.
  20. They allow a 'return 0' in constructors if the object cannot be constructed
  21. and something else.
  22.  
  23. While running a member function one cannot delete the object the function
  24. is working on. After the delete the object the function works with is
  25. not valid any more. So what is the function working with?
  26.  
  27. The output is absolutely correct (if the program not crashes, which is a valid
  28. behaviour in such cases).
  29.  
  30. But why can't you abort the constructor without this delete?
  31. Before throwing the exception you can free all dynamically (inside the
  32. constructor) created things.
  33. Bye.
  34.  
  35.  
  36.